package com.loit.loitcommon.utils;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;

/**
 * @author zhaokz
 * @date 2022/5/16
 */
public class DesUtils {
    private static final String KEY = "telemedicine";
    /**
     * 根据KEY生成DES
     */
    private static DES des =
            SecureUtil.des(
                    SecureUtil.generateKey(SymmetricAlgorithm.DES.getValue(), KEY.getBytes()).getEncoded());

    /**
     * 获取加密后信息
     *
     * @param plainText 明文
     * @return 加密后信息
     */
    public static String getEncryptData(String plainText) {
        return des.encryptHex(plainText);
    }

    /**
     * 获取解密后信息
     *
     * @param cipherText 密文
     * @return 解密后信息
     */
    public static String getDecryptData(String cipherText) {
        return des.decryptStr(cipherText);
    }

    public static void main(String[] args) {
        String str1 = "minio";
        String str2 = "loit2022";
        String encryptData1 = getEncryptData(str1);
        String encryptData2 = getEncryptData(str2);
        System.out.println(encryptData1);
        System.out.println(encryptData2);
        System.out.println(getDecryptData(encryptData1));
        System.out.println(getDecryptData(encryptData2));
    }
}
